<?php

namespace App\Http\Controllers\API\Feedback;

use Auth;
use Validator;
use Illuminate\Http\Request;
use App\Models\Admin\Feedback;
use App\Http\Controllers\API\APIController;

class FeedbackController extends APIController
{
    public function store(Request $request)
    {
    	$v = Validator::make($request->all(), [
			'user_id' => 'required',
			'detail'  => 'required|max:255'
		]);

		if ($v->fails())
		{
			return response()->json($this->setJson(false, $v->errors()), 422);
		}

		if ($v->passes())
		{
			$inputData = $request->all();
			Feedback::create($inputData);
			return response()->json($this->setJson(true, 'feedback_succeed'), 200);
		}
    }

    private function setJson($status, $msg)
    {
        $res = [
            'status' => $status,
            'msg'    => $msg
        ];
        return $res;
    }
}
